package com.attendance.service.impl;

import com.attendance.mapper.EmployeeMapper;
import com.attendance.model.Biz.BizEmployee;
import com.attendance.model.Employee;
import com.attendance.service.IEmployeeService;
import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Employee 表数据服务层接口实现类
 */
@Service
public class EmployeeServiceImpl extends SuperServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {


    @Override
    public Employee getByName(String username) {
        EntityWrapper<Employee> ew = new EntityWrapper<Employee>();
        ew.where("username={0}",username);
        List<Employee> list = this.baseMapper.selectList(ew);
        if(list.size() != 0)
            return list.get(0);
        return null;
    }

    @Override
    public List<BizEmployee> getAll(Employee employee) {
//        EntityWrapper<Employee> ew = new EntityWrapper<Employee>();
//        ew.where("1=1");
//        if(employee.getId() != null){
//            ew.andNew("id={0}",employee.getId());
//        }
//        if(employee.getDepartmentId() != null){
//            ew.andNew("departmentId={0}", employee.getDepartmentId());
//        }
//        if(employee.getName() != null){
//            ew.like("name", employee.getName());
//        }
//        if(employee.getUsername() != null){
//            ew.like("username",employee.getUsername());
//        }
//        if(employee.getJob() != null){
//            ew.andNew("job={0}",employee.getJob());
//        }
//        if(employee.getSex() != null){
//            ew.andNew("sex={0}", employee.getSex());
//        }
//        return this.baseMapper.selectList(ew);
        return this.baseMapper.getAll(employee);
    }
}